<template>
	<view class="salePlan">
		<uni-nav-bar color="#ffffff" background-color="#00aded" :statusBar="true" title="发运物流单" fixed="true" left-icon="left" left-text="返回" @clickLeft="back" />
		<view class="salePlan_top">
			<!-- 搜索 -->
			<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
		</view>
		<view class="salePlan_main">
			<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
		</view>
		<view class="salePlan_floot"></view>
	</view>
</template>

<script>
import { mapMutations } from 'vuex';
export default {
	data() {
		return {
			options: {
				requestUrl: '/api/v1/ams/getSalePlanList?apiId=635',
				requestQuery: {},
				cardSlotList: [
					{
						label: '运输详情',
						icon: 'bars',
						emitEvent: 'transOrderBrowse'
					},
					{
						label: '派车',
						icon: 'wlIcon-paicheguanli',
						emitEvent: 'transOrderAdd'
					},
					{
						label: '删除',
						icon: 'trash',
						emitEvent: 'deleteClick'
					}
				],
				columnDataList: [],
				totalNum: 0
			}
		};
	},
	onShow() {
		uni.$emit('onShow', 1);
	},
	created() {
		this.initialMap = {
			planType: 0,
			status: '正常',
			allowance: 1
		};
		this.options.requestQuery = { ...this.initialMap };
	},
	mounted() {},
	methods: {
		getOrderSectionDebounce() {
			this.options.requestQuery = { ...this.options.requestQuery };
		},
		onSearch(item) {
			this.options.requestQuery = { ...JSON.parse(JSON.stringify(item)), ...this.initialMap };
		},
		async getOrderSection(data = {}) {
			// Object.assign(data,this.$route.query);//菜单url参数带入查询
		},
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		transOrderAdd(item) {
			console.log(item, 'item');
			this.updateSaleTransOrderItem(item);
			uni.navigateTo({
				url: '/pages/transOrder/saleTransOrderAdd'
			});
		},
		transOrderBrowse(item) {
			uni.navigateTo({
				url:
					'/pages/transOrder/saleTransOrder?params=' +
					JSON.stringify({
						planId: item.transPlanId
					})
			});
		},
		deleteClick(item) {
			uni.showModal({
				cancelText: '取消',
				confirmText: '确定',
				content: '是否删除该单据',
				title: '提示',
				success: (res) => {
					if (res.confirm) {
						this.deleteClickRequest(item);
					}
				}
			});
		},
		async deleteClickRequest(item) {
			item.deleted = 2;
			const res = await this.$myRequest({
				url: '/api/v1/ams/purchasePlanChange',
				data: item
			}).catch((err) => {
				uni.showToast({
					duration: 20000,
					title: err,
					icon: 'none'
				});
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				this.getOrderSectionDebounce();
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		},
		//vuex
		...mapMutations('sale', ['updateSaleAppointItem']),
		//vuex
		...mapMutations('sale', ['updateSaleTransOrderItem'])
	}
};
</script>

<style lang="scss" scoped>
.salePlan {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	&_top {
		background-color: #fff;
	}
	&_main {
	}
	&_floot {
	}
}
</style>
